package com.alibb.rule;

import com.alibaba.nacos.client.naming.utils.ThreadLocalRandom;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.AbstractLoadBalancerRule;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;

import java.util.List;

/**
 * 自定义负载均衡
 */
public class CusterRule extends AbstractLoadBalancerRule {


    public Server choose(Object var1) {
        ILoadBalancer loadBalancer = this.getLoadBalancer();
        List<Server> list = loadBalancer.getReachableServers();
        int random = ThreadLocalRandom.current().nextInt(list.size());
        Server server = list.get(random);
        return server;
    }

    public void initWithNiwsConfig(IClientConfig var1) {

    }
}
